package com.epic.pager;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.epic.item.MediaItem;
import com.loopj.android.image.SmartImageView;

public class ImagePager extends Fragment {
	private MediaItem item;
	private View.OnClickListener gestureListener;
	private OnModeZoomListener listener;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.i("ImagePager", "onCreate");
		Bundle bundle = getArguments();
		item = (MediaItem) bundle.getSerializable("MEDIA ITEM");
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		listener = (OnModeZoomListener) activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.i("ImagePager", "onCreateView");
		SmartImageView view = new SmartImageView(this.getActivity()
				.getApplicationContext());
		gestureListener = new View.OnClickListener() {
			private long upTime;
			private long downTime;
			@Override
			public void onClick(View v) {
				upTime = System.currentTimeMillis();
				Log.i("ImagePager","Range = " + (upTime - downTime));
				if (upTime - downTime < 500L) {
					listener.onModeZoomListener(item.img_url);
				} else {
					downTime = upTime;
				}
			}
		};
		view.setOnClickListener(gestureListener);
		view.setImageUrl(item.img_url);
		return view;
	}
	
	@Override
	public void onPause() {
		super.onPause();
		Log.i("ImagePager", "onPause");
	}
	
	public MediaItem getItem() {
		return item;
	}

}
